
package com.platform.modules.app.controller;

import com.alibaba.fastjson.JSONObject;
import com.platform.annotation.LoginUser;
import com.platform.common.utils.RestResponse;
import com.platform.modules.mall.entity.MallUserEntity;
import com.platform.modules.mall.service.MallUserService;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author
 */
@RestController
@RequestMapping("/app/user")
@Api(tags = "AppUserController|APP用户接口")
@Slf4j
public class AppUserController {
    @Autowired
    private MallUserService userService;
    /**
     * 根据token获取当前登录用户信息
     *
     * @param user user
     * @return RestResponse
     */
    @GetMapping("/userInfo")
    @ApiOperation(value = "获取登录用户信息", notes = "根据token获取用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "用户token", required = true, dataType = "string"),
    })
    public RestResponse userInfo(@LoginUser MallUserEntity user) {
        return RestResponse.success().put("data", user);
    }



    @PostMapping("/detectAuth")
    public RestResponse detectAuth(@LoginUser MallUserEntity loginUser , @RequestBody JSONObject param){
        String userId = loginUser.getId();
        String redirectUrl = param.getString("redirectUrl");
        try {
            return userService.detectAuth(redirectUrl, userId);
        } catch (TencentCloudSDKException e) {
            e.printStackTrace();
            return RestResponse.error("网络走丢了，请联系管理员吧！");
        }
    }

    /**
     * 结果查询
     * @param loginUser
     * @return
     */
    @PostMapping("/detectAuthGetRes")
    public RestResponse detectAuthGetRes(@LoginUser MallUserEntity loginUser){
        String userId = loginUser.getId();
        return userService.detectAuthGetRes(userId);
    }
}
